import axios from "../http"
import React from 'react'



// 获取请求数据
export function reqTodo() {
    return axios("/data")
}

// 天机一个数据
export function reqAddTodo(title) {
    return axios.post("/data",{title,done:false})
}

// 删除一个数据
export function reqDeleteTodo(id) {
    return axios.delete(`/data/${id}`)
}

// 修改数据
export function reqUpdateTodo(id,done) {
    return axios.patch(`/data/${id}`,{done})
}

// 全选全不选
export function reqAllTodo(data,done) {
    let promises =  data.map((item) => {
        return axios.patch(`/data/${item.id}`,{done})
        })  
        return  Promise.all(promises)
}

//清楚已完成全选

export function reqClearok(data) {
    let promises = data.filter((item) => item.done).map((item) =>{ axios.delete(`/data/${item.id}`)} )
        return  Promise.all(promises)
}
